package ztools

import (
	"crypto/rand"
	"encoding/binary"
	"os"
	"os/signal"
)

// If 三目运算
func If(condition bool, trueVal interface{}, falseVal interface{}) interface{} {
	if condition {
		return trueVal
	}
	return falseVal
}

func IfFunc(condition bool, func1 func(), func2 func()) {
	if condition {
		func1()
	} else {
		func2()
	}
}

// RandomNumber 随机生成6位数字
func RandomNumber(n int) uint64 {
	var num uint64
	_ = binary.Read(rand.Reader, binary.BigEndian, &num)
	var x = Pow(n-2, 10)
	ret := num%uint64(x*9) + uint64(x)

	return ret
}

func Pow(n, v int) int64 {
	var value = int64(v)
	for i := 1; i <= n; i++ {
		value *= int64(v)
	}
	return value
}

func WaitApplication() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Kill, os.Interrupt)
	<-c
}
